package org.example.ioc.pro6_ioc_conditional;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class SystemCondiyional implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        //context 上下文环境
        //metadata 注解信息
        String userhome = context.getEnvironment().getProperty("user.home");  //获取到当前用户的家目录
        System.out.println("用户家目录"+userhome);
        String userdir = context.getEnvironment().getProperty("user.dir");   //获取到当前项目的目录
        System.out.println("用户"+userdir);
        //获取到当前环境信息  获取当前系统的名称
        String osName = context.getEnvironment().getProperty("os.name");
        if ("Linux".equals(osName)) {
            return false;
        }
        return true;
    }
}
